package hsb.ruoyi.framework.web.service;//package hsb.learn.framework.web.service;
//
//import hsb.learn.common.core.domain.UserNoPwdAuthenticationToken;
//import hsb.learn.common.core.domain.WXAuthenticationToken;
//import hsb.learn.common.core.domain.entity.AppUser;
//import hsb.learn.common.core.domain.model.LoginUser;
//import hsb.learn.system.mapper.AppUserMapper;
//import hsb.learn.system.service.ISysMenuService;
//import lombok.Data;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.stereotype.Component;
//
//import java.util.Set;
//
///**
// * @author 胡帅博
// * @date 2022/9/16 14:35
// */
//@Data
//@Component
//public class AppUserNoPwdProvider implements AuthenticationProvider {
//
//    @Autowired
//    private AppUserMapper userMapper;
//
//    @Autowired
//    private ISysMenuService menuService;
//
//    /**
//     * 这个只需要传递appUserId,就可以登陆，密码，手机验证等操作应该在之前已经完成
//     *
//     * @param authentication
//     * @return
//     * @throws AuthenticationException
//     */
//    @Override
//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//        LoginUser loginUser = (LoginUser) loadUserByAppUserId(authentication.getPrincipal().toString());
//        if (loginUser == null) {
//            throw new RuntimeException("登陆失败");
//        }
//        WXAuthenticationToken wxAuthenticationToken = new WXAuthenticationToken(loginUser);
//        return wxAuthenticationToken;
//    }
//
//
//    private UserDetails loadUserByAppUserId(String userId) throws UsernameNotFoundException {
//        //根据用户名在数据库中查询用户信息
//        AppUser appUser = userMapper.selectById(Long.valueOf(userId));
//        Set<String> perms = menuService.selectMenuPermsByRoleName(appUser.getRole());
//        //或者后台配置appuser角色的权限
//        LoginUser loginUser = new LoginUser(appUser.getId(), 100L, appUser, perms);
//        return loginUser;
//    }
//
//    /**
//     * 配置当前Provider对应的wxAuthenticationToken
//     *
//     * @param authentication
//     * @return
//     */
//    @Override
//    public boolean supports(Class<?> authentication) {
//        return (UserNoPwdAuthenticationToken.class.isAssignableFrom(authentication));
//    }
//
//}
